package test.h0818;

import java.util.*;

public class Main1 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s = sc.nextLine();
        int[] nums = Arrays.stream(s.split(",")).mapToInt(Integer::parseInt).toArray();
        int jump = Integer.parseInt(sc.nextLine());
        int surivivors=Integer.parseInt(sc.nextLine());
        System.out.println(getResult(nums, jump, surivivors));

    }

    private static int getResult(int[] nums, int jump, int surivivors) {
        //要求的幸存数之和比数组长度大
        if (surivivors> nums.length){
            return Arrays.stream(nums).sum();
        }

        //初始化一个List
        List<Integer> list=new ArrayList<>();
        for (int num : nums) {
            list.add(num);
        }
        int index=1; //从1开始，因为这里是跳数，如果从0开始逻辑不对
        while (list.size()>surivivors){
            index+=jump; //跳jump下
            index=index%list.size();
            list.remove(index);
        }
        return list.stream().mapToInt(Integer::intValue).sum();
    }
}
